package com.xiaohei.crm.common.exception;

import com.xiaohei.crm.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * ClassName: XiaoheiException
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/4/22 15:27
 * Version 1.0
 */
@Data
public class XiaoheiException extends RuntimeException{

    private Integer code;//状态码
    private String msg;//描述信息

    /**
     * 通过状态码和描述信息构造异常
     * @param code
     * @param msg
     */
    public XiaoheiException(Integer code, String msg){
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    /**
     * 通过枚举对象创建异常方法
     * @param resultCodeEnum
     */
    public XiaoheiException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMessage();
    }

    public String toString(){
        return "XiaoheiException{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }

}
